//
//  RWDock.m
//  04-ipadQQ
//
//  Created by 紫荆秋雪 on 16/4/7.
//  Copyright © 2016年 紫荆秋雪. All rights reserved.
//

#import "RWDock.h"
#import "RWIconImage.h"
#import "RWTabBar.h"
#import "RWToolBar.h"

@interface RWDock ()

/**
 *  RWIconImage
 */
@property (nonatomic,weak)  RWIconImage *iconImage;

/**
 *  RWTabBar
 */
@property (nonatomic,weak)  RWTabBar *tabBar;

/**
 *  RWToolBar
 */
@property (nonatomic,weak)  RWToolBar *toolBar;

@end

@implementation RWDock

- (instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if (self) {
        //1、设置背景颜色
//        self.backgroundColor = RWRandomColor;
        
        //2、创建 RWIconImage
        RWIconImage *iconImage = [[RWIconImage alloc] init];
        
        [self addSubview:iconImage];
        self.iconImage = iconImage;
        
        //3、创建 RWTabBar
        RWTabBar *tabBar = [[RWTabBar alloc] init];
        
        [self addSubview:tabBar];
        
        self.tabBar = tabBar;
        
        //4、 创建 RWToolBar
        RWToolBar *toolBar = [[RWToolBar alloc] init];
        
        [self addSubview:toolBar];
        self.toolBar = toolBar;
        
    }
    return self;
}

/**
 *  给子控件布局
 */
- (void)layoutSubviews{

    [super layoutSubviews];
    
    self.iconImage.width = self.width;
    self.tabBar.width = self.width;
    self.toolBar.width = self.width;
    //判断屏幕方向
    if (Lanscape) {//横向
        //1、RWIconImage布局
        self.iconImage.x = 0;
        self.iconImage.y = 0;
        self.iconImage.height = self.height * 1.0 / self.subviews.count;
        
        //2、RWToolBar
        self.toolBar.height = self.width / 3;
        self.toolBar.x = 0;
        self.toolBar.y = self.height - self.toolBar.height;

        //3、RWTabBar布局
        self.tabBar.x = 0;
        self.tabBar.y = CGRectGetMaxY(self.iconImage.frame);
        
        self.tabBar.height = self.height - self.iconImage.height - self.toolBar.height;
        
    }else {//竖向
    
        //1、RWIconImage布局
        self.iconImage.x = 0;
        self.iconImage.y = 0;
        self.iconImage.height = self.height * 1.0 / self.subviews.count;
        
        //2、RWToolBar
        self.toolBar.height = self.width * 3;
        self.toolBar.x = 0;
        self.toolBar.y = self.height - self.toolBar.height;
        
        //3、RWTabBar布局
        self.tabBar.x = 0;
        self.tabBar.y = CGRectGetMaxY(self.iconImage.frame);
        
        self.tabBar.height = self.height - self.iconImage.height - self.toolBar.height;
        
    }
    
}

@end
